<?php

/**
 * uniBoard New Imageset
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-08 03:38:35 +0000 (Wed, 08 Sep 2010) $
 * $Revision: 60 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_new_imageset{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	/**
	 * Settings group API
	 *
	 * @var object
	 */
	
	private $api			= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
	
		// Start Style API
		$this -> api = new api_imageset( $appCore);
		
		// Set Imageset name
		$this -> api -> setImagesetName( $appCore -> _POST( 'new_imageset_name'));
		
		// Error?
		if ( $this -> api -> error)
		{
			// Draw error
			$appCore -> output -> error( $this -> api -> last_error, $appCore -> lang['new_imageset_form']);
			
			// Draw form
			$this -> drawForm();			
		}
		else
		{
			// Save API
			$this -> api -> saveData();
			
			// Create new empty directory
			class_files::newDir( STYLES_DATA_PATH . 'imageset_' . $this -> api -> imageset_id);
			
			// Create Log
			$appCore -> logAdmin( 'log_admin_new_imageset', htmlspecialchars( $this -> api -> imageset_name));
					
			// Redirect
			$appCore -> output -> drawRedirect( $appCore -> adminLink( 'act=images'), $appCore -> lang['acp_imageset_new_created']);
		}
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Draws new imageset form
	 *
	 */
	
	function drawForm(){
		
		// Load fields templates
		$this -> appCore -> templates['form_inputs'] = new tpl_form_inputs( $this -> appCore);
		
		// Cache output
		ob_start();
		
		// New style form start
		echo $this -> appCore -> output -> openForm( $this -> appCore -> adminLink( 'act=new_imageset', true));
		echo $this -> appCore -> output -> openFormBlock( $this -> appCore -> lang['new_imageset_form']);
		
		// Draw field
		echo $this -> appCore -> output -> formItem( $this -> appCore -> lang['new_imageset_form_name'], $this -> appCore -> drawTextInput( 'new_imageset_name', $this -> api -> imageset_name), $this -> appCore -> lang['new_imageset_form_name_expl']);
		
		// New style form close
		echo $this -> appCore -> output -> submitButton( $this -> appCore -> lang['new_imageset_form_submit']);
		echo $this -> appCore -> output -> closeFormBlock();
		echo $this -> appCore -> output -> closeForm();
		
		// Draw output
		$this -> appCore -> output -> draw( $this -> appCore -> lang['new_imageset_form'], array( $this -> appCore -> adminLink( 'act=images') => $this -> appCore -> lang['new_imageset_form'], $this -> appCore -> lang['new_imageset_form']), ob_get_clean());
		
	}
	
}